package top.swimmer.tools.data.linked;

public class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }

//    @Override
//    public String toString() {
//        return val + "->" + next;
//    }

    public static ListNode getOne() {
        ListNode node1 = new ListNode(1);
        return node1;
    }

    public static ListNode getTwo() {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        node1.next = node2;
        return node1;
    }

    public static ListNode get(int... numbers) {
        ListNode parent = new ListNode(0);
        ListNode prev = parent;
        for (int number : numbers) {
            ListNode node = new ListNode(number);
            prev.next = node;
            prev = node;
        }
        return parent.next;
    }

    public static ListNode get() {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(5);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        return node1;
    }
}
